package base.Stream流;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class 练习_1 {
    public static void main(String[] args) {

        //1、过滤奇数
        ArrayList<Integer> list1 = new ArrayList<>();
        Collections.addAll(list1,1,2,3,4,5,6,7,8,9,10);
        list1.stream().filter(new Predicate<Integer>() {
            @Override
            public boolean test(Integer i) {
                return i%2==0;
            }
        });


        //2、保留年龄大于等于24岁的人，并将集合收集到Map集合，姓名为键，年龄为值
        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2,"zhangsan,23","lisi,24","wangwu,25");
        Map<String, String> map = list2.stream().filter(s -> Integer.parseInt(s.split(",")[1]) >= 24)
                .collect(Collectors.toMap(
                        s -> s.split(",")[0],
                        s -> s.split(",")[1]
                ));
        System.out.println(map);



    }
}
